﻿using System;
using System.Linq;
using Splendor_Server.script.logic.data;

namespace Splendor_Server.script.logic
{
    public static class GameSpawn
    {
        public static int[] nobleOrder;

        private const int NobleCnt = 14;

        public static int[] mineOrderLevel1;

        private const int MineLevel1Cnt = 40;

        public static int[] mineOrderLevel2;

        private const int MineLevel2Cnt = 30;

        public static int[] mineOrderLevel3;

        private const int MineLevel3Cnt = 20;

        public static void Init()
        {
            nobleOrder = new int[NobleData.data.Keys.Count];
            for (int i = 1; i <= NobleCnt; i++)
            {
                nobleOrder[i - 1] = i;
            }

            mineOrderLevel1 = new int[40];
            for (int i = 1; i <= MineLevel1Cnt; i++)
            {
                mineOrderLevel1[i - 1] = i;
            }

            mineOrderLevel2 = new int[30];
            for (int i = 1; i <= MineLevel2Cnt; i++)
            {
                mineOrderLevel2[i - 1] = i;
            }

            mineOrderLevel3 = new int[20];
            for (int i = 1; i <= MineLevel3Cnt; i++)
            {
                mineOrderLevel3[i - 1] = i;
            }
        }

        public static int[] ShuffleArray(int[] arr)
        {
            int n = arr.Length;

            for (int i = n - 1; i >= 0; i--)
            {
                int rand = new Random().Next(0, i);
                int tmp = arr[i];
                arr[i] = arr[rand];
                arr[rand] = tmp;
            }

            return arr;
        }

        private static int[] setup = {3, 4, 5};

        public static int[] GetExtraOrder(int num)
        {
            return ShuffleArray(nobleOrder).Take(setup[num - 2]).ToArray();
        }
    }
}